//
//  YWVerticalButton.m
//  YueshengToutiao
//
//  Created by yellow on 2021/4/26.
//  Copyright © 2021 YW. All rights reserved.
//

#import "YWVerticalButton.h"

// 图标的比例
#define MyTabBarButtonImageRatio 55/70
@implementation YWVerticalButton


-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        //图标居中
        self.imageView.contentMode = UIViewContentModeCenter;
        
        //文字居中
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        
        //字体大小
        self.titleLabel.font = [UIFont systemFontOfSize:12];
        
        //文字颜色
        [self setTitleColor:YWColor(51, 51, 51) forState:UIControlStateNormal];
        [self setTitleColor:YWColor(51, 51, 51) forState:UIControlStateSelected];

    }

    return self;
}

//假如是xib创建的
-(instancetype)initWithCoder:(NSCoder *)aDecoder{

    if (self = [super initWithCoder:aDecoder]) {
        
        //图标居中
        self.imageView.contentMode = UIViewContentModeCenter;
        
        //文字居中
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        
        //字体大小
        self.titleLabel.font = [UIFont systemFontOfSize:12];
        
        //文字颜色
        [self setTitleColor:YWColor(51, 51, 51) forState:UIControlStateNormal];
        [self setTitleColor:YWColor(51, 51, 51) forState:UIControlStateSelected];
        
        
    }
    return self;

}

//重写取消高亮
- (void)setHighlighted:(BOOL)highlighted{}

//设置内部图片frame
- (CGRect)imageRectForContentRect:(CGRect)contentRect{
    CGFloat imageW = contentRect.size.width;
    CGFloat imageH = contentRect.size.height * MyTabBarButtonImageRatio;
    return CGRectMake(0, 0, imageW, imageH);
}
//设置内部文字frame
- (CGRect)titleRectForContentRect:(CGRect)contentRect{
    CGFloat titleY = contentRect.size.height * MyTabBarButtonImageRatio + 5;
    CGFloat titleW = contentRect.size.width;
    CGFloat titleH = contentRect.size.height - titleY;
    return CGRectMake(0, titleY, titleW, titleH);
}

@end
